package cn.openea.perpartner.sysuser.controller;

import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.system.entity.SysUser;
import cn.openea.perpartner.sysuser.service.IAppletsService;
import cn.openea.perpartner.sysuser.domain.UserDto;
import cn.openea.perpartner.sysuser.domain.LoginBody;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * @author Administrator
 */
@RestController
@RequestMapping("/applets")
@Api(tags = "小程序认证")
public class AppletsController extends BaseController {

    @Autowired
    IAppletsService appletsService;

    @ApiOperation("用户登录")
    @PostMapping(value = "/login")
    public JSONObject login(@RequestBody LoginBody loginBody) {

        return appletsService.login(loginBody);
    }
    @ApiOperation("三方登录")
    @PostMapping(  "/thirdParty/login")
    public JSONObject thirdPartyLogin(@RequestBody LoginBody loginBody) {

        return appletsService.thirdPartyLogin(loginBody);
    }



    @PostMapping(value = "/create")
    public AjaxResult createUser(@RequestBody SysUser user){
        return appletsService.createUser(user);
    }
    @PostMapping(value = "/delete")
    public AjaxResult deleteUsers(@RequestBody List<String> idList){
        return appletsService.deleteUsers(idList);
    }
    @ApiOperation("更新手机")
    @PostMapping(value = "/save")
    public JSONObject saveUserInfo(@RequestBody UserDto dto) {

        return appletsService.saveUserInfo(dto);
    }

    @ApiOperation("同步bpm用户")
    @GetMapping(value = "/async/single/{userId}/{appId}")
    @ResponseBody
    public AjaxResult singleSync(@PathVariable String userId,@PathVariable String appId) {

        return appletsService.singleSync(userId,appId) ? success() : error("同步失败！请检查当前用户id是否存在！");
    }

    @PostMapping(value = "/async/batch", consumes = "application/json")
    @ResponseBody
    public AjaxResult batchAsync() {
        return toAjax(appletsService.batchAsync());
    }


}
